<template>
	<view class="container">
		<view class="popup_group">
			<view class="popup_group_item" v-for="(item, index) in seats">
				<view class="popup_group_item_label">{{item.seatNo}}号</view>
				<view class="popup_group_item_value" style="display: flex; flex-direction: column;">
					<radio-group @change="onUseDeviceChange($event, index)" style="display: flex;">
						<label style="display: flex;">
							<view><radio value=0 :checked="0 == item.useDevice" /></view>
							<view>无设备</view>
						</label>
						<label style="display: flex; margin-left: 20rpx;">
							<view><radio value=1 :checked="1 == item.useDevice" /></view>
							<view>有设备</view>
						</label>
					</radio-group>
                    <view class="popup_group_item" v-if="1 == item.useDevice">
						<view class="popup_group_item_label">设备编号：</view>
                        <view class="popup_group_item_value scancode" @click="onTapScan(index)">{{item.deviceSn?item.deviceSn:'点击扫码'}}</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="handle dobuButton">
			<view class="handle_button margin_right" @click="onCancel">取消</view>
			<view class="handle_button" @click="onOK">确定</view>
		</view>
		
	</view>
</template>

<script>
const app = getApp();	
import { Toast, setStorage, navigateBack, getStorage } from '../../../libs/uniApi.js';
import avatar from "@/components/yq-avatar/yq-avatar.vue";
import {TOKENNAME, HTTP_REQUEST_URL} from '@/config/app.js';
import store from '@/store';
import {genDefaultPartition,genDefaultPartitionPrice} from '../../../components/ssty/common.js'
export default {
	components: {
		avatar
	},
	data() {
		return {
			seats: []
		};
	},
	onLoad(opt) {
		console.log("ypSeat::onLoad, app.globalData.ypSeats=%o", app.globalData.ypSeats);
		this.seats = JSON.parse(JSON.stringify(app.globalData.ypSeats));
	},
	onShow() {
	},
	watch: {
		seats: {
			handler(val) {
				this.seats = val;
			},
			deep: true
		},
	},
	methods: {
		onUseDeviceChange(e, index) {
			console.log("onUseDeviceChange", e, index);
			this.seats[index].useDevice = parseInt(e.detail.value);
		},
		onTapScan(index) {
			let that = this;
            uni.scanCode({
                success: function (res) {
                    console.log('onTapScan, 条码类型：' + res.scanType + ', 条码内容：' + res.result);
                    if(res.result && res.result.indexOf("DY*") === 0)
                        that.seats[index].deviceSn = res.result;
                }
            });
		},
		onCancel() {
			navigateBack(1);
		},
		onOK() {
			app.globalData.ypSeats = this.seats;
			navigateBack(1);
		}
	}
};
</script>

<style lang="scss" scoped>
@import './scss/index.scss';

.scancode {
	background-color: #E93323;
	color: white;
	padding: 10rpx;
	border-radius: 10rpx;
}

</style>
